from mpmath import mp

from ..helpers import article
from ._helpers import TriangleScheme, concat, s1, s2, s3

citation = article(
    authors=["Linbo Zhang", "Tao Cui", "Hui Liu"],
    title="A set of symmetric quadrature rules on triangles and tetrahedra",
    journal="Journal of Computational Mathematics",
    volume="27",
    number="1",
    month="jan",
    year="2009",
    pages="89-96",
    url="https://www.jstor.org/stable/43693493",
)


def zhang_cui_liu_1(mpmath=False):
    flt = mp.mpf if mpmath else float

    mp.dps = 35
    weights, points = concat(
        s3(flt("0.1443156076777871682510911104890646")),
        s2(
            [
                flt("0.1032173705347182502817915502921290"),
                flt("0.1705693077517602066222935014914645"),
            ],
            [
                flt("0.0324584976231980803109259283417806"),
                flt("0.0505472283170309754584235505965989"),
            ],
            [
                flt("0.0950916342672846247938961043885843"),
                flt("0.4592925882927231560288155144941693"),
            ],
        ),
        s1(
            [
                flt("0.0272303141744349942648446900739089"),
                flt("0.2631128296346381134217857862846436"),
                flt("0.0083947774099576053372138345392944"),
            ]
        ),
    )
    return TriangleScheme("Zhang-Cui-Liu 1", weights, points, 8, citation)


def zhang_cui_liu_2(mpmath=False):
    flt = mp.mpf if mpmath else float

    mp.dps = 35
    weights, points = concat(
        s3(flt("0.0585962852260285941278938063477560")),
        s2(
            [
                flt("0.0017351512297252675680618638808094"),
                flt("0.0099797608064584324152935295820524"),
            ],
            [
                flt("0.0261637825586145217778288591819783"),
                flt("0.4799778935211883898105528650883899"),
            ],
            [
                flt("0.0039197292424018290965208275701454"),
                flt("0.1538119591769669000000000000000000"),
            ],
            [
                flt("0.0122473597569408660972869899262505"),
                flt("0.0740234771169878100000000000000000"),
            ],
            [
                flt("0.0281996285032579601073663071515657"),
                flt("0.1303546825033300000000000000000000"),
            ],
            [
                flt("0.0508870871859594852960348275454540"),
                flt("0.2306172260266531342996053700983831"),
            ],
            [
                flt("0.0504534399016035991910208971341189"),
                flt("0.4223320834191478241144087137913939"),
            ],
        ),
        s1(
            [
                flt("0.0170636442122334512900253993849472"),
                flt("0.7862373859346610033296221140330900"),
                flt("0.1906163600319009042461432828653034"),
            ],
            [
                flt("0.0096834664255066004075209630934194"),
                flt("0.6305521436606074416224090755688129"),
                flt("0.3623231377435471446183267343597729"),
            ],
            [
                flt("0.0363857559284850056220113277642717"),
                flt("0.6265773298563063142335123137534265"),
                flt("0.2907712058836674150248168174816732"),
            ],
            [
                flt("0.0069646633735184124253997225042413"),
                flt("0.9142099849296254122399670993850469"),
                flt("0.0711657108777507625475924502924336"),
            ],
        ),
    )
    return TriangleScheme("Zhang-Cui-Liu 2", weights, points, 14, citation)


def zhang_cui_liu_3(mpmath=False):
    flt = mp.mpf if mpmath else float

    mp.dps = 35
    weights, points = concat(
        s3(flt("0.0125376079944966565735856367723948")),
        s2(
            [
                flt("0.0274718698764242137484535496073598"),
                flt("0.2158743059329919731902545438401828"),
            ],
            [
                flt("0.0097652722770514230413646914294237"),
                flt("0.0753767665297472780972854309459163"),
            ],
            [
                flt("0.0013984195353918235239233631597867"),
                flt("0.0103008281372217921136862160096969"),
            ],
            [
                flt("0.0092921026251851826304282034030330"),
                flt("0.4936022112987001655119208321450536"),
            ],
            [
                flt("0.0165778760323669253260236250351840"),
                flt("0.4615509381069252967410487102915180"),
            ],
        ),
        s1(
            [
                flt("0.0206677623486650769614219700129729"),
                flt(".3286214064242369933034974609509133"),
                flt(".4293405702582103752139588004663984"),
            ],
            [
                flt("0.0208222355211545073068785561993297"),
                flt(".2604803617865687564195930170811535"),
                flt(".1015775342809694461687550061961797"),
            ],
            [
                flt("0.0095686384198490606888758450458320"),
                flt(".1370742358464553000000000000000000"),
                flt(".7100659730011301599879040745464079"),
            ],
            [
                flt("0.0244527709689724638856439207024089"),
                flt(".1467269458722997843041609884874530"),
                flt(".4985454776784148493896226967076119"),
            ],
            [
                flt("0.0031557306306305340038264003207296"),
                flt(".0269989777425532900000000000000000"),
                flt(".0491867226725820016197037125775872"),
            ],
            [
                flt("0.0121367963653212969370133090807574"),
                flt(".0618717859336170268417124700122339"),
                flt(".7796601465405693953603506190768108"),
            ],
            [
                flt("0.0149664801438864490365249118515707"),
                flt(".0477243674276219962083526801042934"),
                flt(".3704915391495476369201496202567388"),
            ],
            [
                flt("0.0063275933217777395693240327504398"),
                flt(".1206005151863643799672337870400794"),
                flt(".8633469487547526484979879960925217"),
            ],
            [
                flt("0.0013425603120636958849798512981433"),
                flt(".0026971477967097876716489145012827"),
                flt(".0561949381877455029878923019865887"),
            ],
            [
                flt("0.0027760769163475540677293561558015"),
                flt(".0030156332779423626572762598234710"),
                flt(".2086750067484213509575944630613577"),
            ],
            [
                flt("0.0107398444741849415551734474479517"),
                flt(".0299053757884570188069287738643386"),
                flt(".7211512409120340910281041502050941"),
            ],
            [
                flt("0.0053678057381874532052474100212697"),
                flt(".0067566542224609885399458175192278"),
                flt(".6400554419405418899040536682721647"),
            ],
        ),
    )
    return TriangleScheme("Zhang-Cui-Liu 3", weights, points, 20, citation)
